"use strict";
const way = require("./utils/way");
const HomeCtl = require("./controller/home");

//添加埋点
exports.addTrack = async (context) => {
	//   return await way.execute(HomeCtl, "addTrack", context);
	let { data, cloud, mixNick } = context;
	data.data.userId = mixNick;
	console.log("===data===", data.data);
	const result = await cloud.httpApi.invoke(
		{
			'domain': "https://go-tracking-kafka.morefun.me",
			'path': '/go-tracking-mq-gateway/api/v2.1/tracking/rocket/tcp/producer/str',
			'params': '',
			'method': 'POST',
			'headers': {
				'Content-Type': 'application/json;charset=UTF-8',
			},
			'body': {
				"buried_point_data": JSON.stringify(data.data)
			}
		});
	return result

};


//添加埋点
exports.addTrack2 = async (context) => {
	//   return await way.execute(HomeCtl, "addTrack", context);
	let { data, cloud, mixNick } = context;
	// data.data.userId = mixNick;
	console.log("===data===", data.data);
	data.data.device = data.data.device.toLowerCase();
	const result = await cloud.httpApi.invoke(
		{
			'domain': "https://go-tracking-kafka.morefun.me",
			'path': '/go-tracking-mq-gateway/api/v2.1/tracking/rocket/tcp/producer/str',
			'params': '',
			'method': 'POST',
			'headers': {
				'Content-Type': 'application/json;charset=UTF-8',
			},
			'body': {
				"buried_point_data": JSON.stringify(data.data)
			}
		});
	return result

};


//是否展示
exports.findIsShow = async (context) => {
	return { code: 200, msg: "成功", data: true };
};
// //添加埋点
// exports.gtcut = async (context) => {
//   let { openId, cloud } = context;
//   cloud.topApi.client.appkey = '34300180';
//   cloud.topApi.client.appsecret = '5569364da519c80c0cdddc2dfd639a73';
//   let data = {
//     'name': 'morefun',
//     'handler': 'gtcut',
//     'env': 'test',
//     'data': { "openId": openId }
//   };
//   console.log("call data", openId);
//   const result = await way.taobaoInvoke(cloud, "taobao.miniapp.cloud.function.invoke", data);
//   console.log("call result", result);
//   return result;
// };
// //添加埋点
// exports.mark = async (context) => {
//   let { openId, cloud } = context;
//   cloud.topApi.client.appkey = '32903603';
//   cloud.topApi.client.appsecret = '975723d4e1b3ec9b5414c9a323493cf7';
//   let data = {
//     'session':'50000800147dzetToObULDqDIFsVMvih3hzemUBvPlBGby9kVxTEE1b0RIM10a179d0D',
//     'hit': true,
//     'open_user_ids': [openId],
//     'item_id': '694331629322',
//     'sku_id': "0",
//     'status': 'MARK'
//   };
//   console.log("mark data", data);
//   const res = await way.taobaoInvoke(cloud, "taobao.opentrade.special.users.mark", data);
//   console.log("mark results", res);
//   if (res.result) {
//     res.code = 200;
//   }
//   return res;
// };